<?php
	header("Cache-Control: no-cache, must-revalidate");
	$doc	=	new DOMDocument();
	if($_POST) {
		if ($_POST['inputNome'] != '--' && $_POST['textoMensagem'] != ""){
			$doc->Load('/var/www/constructore/configuracao/idioma/pt-br.xml');
			$listaRaiz	=	$doc->getElementsByTagName('vocabulario');
			$raiz 	=	$listaRaiz->item(0);
			
			$xpath	=	new DOMXPath($doc);
			$query	=	'/vocabulario/define[@id="' . $_POST['inputNome'] . '"]';
			$elemento	=	$xpath->query($query);
			
			$novoEmemento	=	$doc->createElement('define', stripslashes($_POST['textoMensagem']));
			$novoEmemento->setAttribute('id',$_POST['inputNome']);
			$novoEmemento->setIdAttribute('id',true);
			
			$raiz->replaceChild($novoEmemento, $elemento->item(0));
			$doc->save('/var/www/constructore/configuracao/idioma/pt-br.xml');
		}
	}
	$doc->Load('/var/www/constructore/configuracao/idioma/pt-br.xml');
	$defines			=	$doc->getElementsByTagName('define');
	$arrayDefinicoes	=	array();
	for($i = 0; $i < $defines->length; $i++) {
		$arrayDefinicoes[$i]	=	$defines->item($i)->getAttribute('id');
	}
	sort($arrayDefinicoes);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
		<link href="./estilo.css" type="text/css" rel="stylesheet" />
        <title>
            Textos da Constructore
        </title>
    </head>
    <body>
    <ul>
        <li>
            <a href="index.php">
                Inserir
            </a>
        </li>
        <li>
            <a href="editar.php">
                Editar
            </a>
        </li>
		<li>
            <a href="/constructore/configuracao/idioma/pt-br.xml" target="_blank">
                ver Todos
            </a>
        </li>
    </ul>
    <div id="divSite">
        <form id="formPrincipal" method="post" action="" enctype="multipart/form-data">
            <fieldset id="fieldsetForm1">
                <legend>
                    Mensagens
                </legend>
                <div id="divItemForm1">
                    <label class="labelItemObrigatorioForm1">Identificador:</label>
                    <select class="selectForm1" name="inputNome" onchange="javascript:carrega(this.value);">
                    	<option>
                    		--
						</option>
                    	<?php
							foreach ($arrayDefinicoes as $definicao) {
								?>
								<option value="<?php echo $definicao; ?>">
									<?php echo $definicao ?>
								</option>
								<?php
							}
						?>
					</select>
                </div>
                <div id="divItemForm1">
                    <label class="labelItemObrigatorioForm1">Texto:</label>
                    <textarea id="textoMensagem" class="textareaForm1" name="textoMensagem" cols="100" rows="20"></textarea>
                </div>
                <input type="submit" class="btnForm1" value="Salvar"/>
            </fieldset>
        </form>
    </div>
	<script type="text/javascript" src="./definicoes.js" class="btnForm1"></script>
    </body>
</html>